﻿// HSS.Interlink.SafeNavigator.cs
// ----------------------------------------------------------------------------
// Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.html)
// ----------------------------------------------------------------------------
// HighSpeed-Solutions, LLC
// Copyright (c) 2001-2010
// ----------------------------------------------------------------------------
// File:       SafeNavigator.cs
// Author:     HSS\gbanta
// Created:    07/16/2011
// Modified:   07/22/2011
// ----------------------------------------------------------------------------
using System;
using System.Windows.Controls;

namespace HSS.Interlink
{
	/// <summary>
	/// Navigates to an external Uri.
	/// </summary>
	internal sealed class SafeNavigator : HyperlinkButton
	{
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="uri">The uri to navigate to.</param>
		private SafeNavigator(Uri uri)
			: this(uri, false)
		{
		}
		/// <summary>
		/// Constructor
		/// </summary>
		private SafeNavigator(Uri uri, bool newWindow)
		{
			this.NavigateUri = uri;
			if (newWindow)
				this.TargetName = "_blank";
		}
		/// <summary>
		/// Navigate to the requested Uri.
		/// </summary>
		/// <param name="uri">The uri to navigate to.</param>
		public static void Navigate(Uri uri)
		{
			new SafeNavigator(uri).Navigate();
		}
		/// <summary>
		/// Navigate to the requested Uri.
		/// </summary>
		/// <param name="uri">The uri to navigate to.</param>
		/// <param name="newWindow">true to open Uri in a new window.</param>
		public static void Navigate(Uri uri, bool newWindow)
		{
			new SafeNavigator(uri, newWindow).Navigate();
		}
		/// <summary>
		/// Navigate the specified Uri
		/// </summary>
		void Navigate()
		{
			this.OnClick();
		}
		/// <summary>
		/// Provides handling for the System.Windows.Controls.Primitives.ButtonBase.Click event.
		/// </summary>
		protected override void OnClick()
		{
			base.OnClick();
		}
	}
}